/* ------------------------------------------------------------
	TANG -- a demo midware for learning or just for fun :)
		Copyright (C) 2002-2003 BCL Group and Sunribo
 
		This file is part of BCL.
 
	===========================================================
 
	Revision        1.0     2002/12/28
	Initial checkin.
   ------------------------------------------------------------
 */



/*--------------------------	TOOLS OPTION	---------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <strings.h>
#include <time.h>
#include <errno.h>

#define	ULOGDIR	"APPDIR"

void ulog( char *fmt, ... )
{
	static char filename[1024], prefix[32]; char *logdir = NULL;
	extern char instance[128];

	va_list args;  FILE *fp;
	time_t curtime = time(NULL);

	if( (logdir = getenv(ULOGDIR)) == NULL )
		logdir = ".";

	sprintf(filename,"%s%s",logdir, "/RLOG");
	strftime((filename+strlen(filename)),10,".%y%m%d",localtime(&curtime));

	if ((fp = fopen(filename,"aw")) == NULL) {
		fprintf(stderr,"Can't open log file:[%s]\n",filename);
		return;
	}

	va_start( args, fmt );
	strftime( prefix,10,"%H%M%S",localtime(&curtime));
	fprintf( fp, "%s.%s!%d: ", prefix, instance, (int)getpid() );
	vfprintf( fp, fmt, args );
	va_end( args );


	fclose(fp);
}

